package com_.dxy_test_.static_proxy_;

/**
 * @Description 静态代理示例
 * @Author dangxianyue
 * @Date 2022/9/25 0:20
 */
public class StaticProxyTest {

    public static void main(String[] args) {
        Suitor suitor = new Suitor();
        ProxyEnhancer proxy = new ProxyEnhancer(suitor);
        proxy.send("小丽");
        //我是代理我好哥们来向你表白的：
        //Hi, 小丽, 我喜欢你，做我女朋友吧！
    }
}

/**
 * 送情书表白接口
 */
interface LoveLetter {
    void send(String name);
}

/**
 * 追求者，被代理者
 */
class Suitor implements LoveLetter {

    @Override
    public void send(String name) {
        System.out.println("Hi, " + name + ", 我喜欢你，做我女朋友吧！");
    }
}

/**
 * 代理增强类
 * 封装增强逻辑
 */
class ProxyEnhancer implements LoveLetter {

    private Suitor suitor;

    public ProxyEnhancer(Suitor suitor) {
        this.suitor = suitor;
    }

    @Override
    public void send(String name) {
        //增强逻辑
        System.out.println("我是代理我好哥们来向你表白的：");
        suitor.send(name);
    }
}
